#pragma once

#include "../umlmodel_global.h"

#include <memory>
#include <vector>

#include "Class.h"

using std::make_shared;
using std::shared_ptr;
using std::vector;

namespace uml {
class ComponentRealization;
class Interface;
class PackageableElement;

/// <summary>
/// Component
/// A Component represents a modular part of a system that encapsulates its contents
/// and whose manifestation is replaceable within its environment.  
/// </summary>
class UMLMODEL_EXPORT Component : public Class {

public: // Constructors and destructors
    explicit Component(const QString& umlType="uml::Component");

public: // JsonSerializable override
    void fromJson(const QJsonObject& json, QStringList& errorList) override;
    void toJson(QJsonObject& json) override;

public: // Methods
public: // Properties
    /// <summary>
    /// isIndirectlyInstantiated getter
    /// If true, the Component is defined at design-time, but at run-time (or
    /// execution-time) an object specified by the Component does not exist, that is,
    /// the Component is instantiated indirectly, through the instantiation of its
    /// realizing Classifiers or parts.
    /// </summary>
    bool isIndirectlyInstantiated() const;

    /// <summary>
    /// isIndirectlyInstantiated setter
    /// If true, the Component is defined at design-time, but at run-time (or
    /// execution-time) an object specified by the Component does not exist, that is,
    /// the Component is instantiated indirectly, through the instantiation of its
    /// realizing Classifiers or parts.
    /// </summary>
    void setIsIndirectlyInstantiated(bool value);

    /// <summary>
    /// packagedElements getter
    /// The set of PackageableElements that a Component owns. In the namespace of a
    /// Component, all model elements that are involved in or related to its definition
    /// may be owned or imported explicitly. These may include e.g., Classes,
    /// Interfaces, Components, Packages, UseCases, Dependencies (e.g., mappings), and
    /// Artifacts.
    /// </summary>
    vector<shared_ptr<PackageableElement>>& packagedElements();

    /// <summary>
    /// provided getter
    /// The Interfaces that the Component exposes to its environment. These Interfaces
    /// may be Realized by the Component or any of its realizingClassifiers, or they may
    /// be the Interfaces that are provided by its public Ports.
    /// </summary>
    vector<shared_ptr<Interface>>& provided();

    /// <summary>
    /// realizations getter
    /// The set of Realizations owned by the Component. Realizations reference the
    /// Classifiers of which the Component is an abstraction; i.e., that realize its
    /// behavior.
    /// </summary>
    vector<shared_ptr<ComponentRealization>>& realizations();

    /// <summary>
    /// required getter
    /// The Interfaces that the Component requires from other Components in its
    /// environment in order to be able to offer its full set of provided functionality.
    /// These Interfaces may be used by the Component or any of its
    /// realizingClassifiers, or they may be the Interfaces that are required by its
    /// public Ports.
    /// </summary>
    vector<shared_ptr<Interface>>& required();

private: // Fields
    /// <summary>
    /// isIndirectlyInstantiated
    /// If true, the Component is defined at design-time, but at run-time (or
    /// execution-time) an object specified by the Component does not exist, that is,
    /// the Component is instantiated indirectly, through the instantiation of its
    /// realizing Classifiers or parts.
    /// </summary>
    const static bool isIndirectlyInstantiated_default_;
    bool isIndirectlyInstantiated_= isIndirectlyInstantiated_default_;

    /// <summary>
    /// packagedElements
    /// The set of PackageableElements that a Component owns. In the namespace of a
    /// Component, all model elements that are involved in or related to its definition
    /// may be owned or imported explicitly. These may include e.g., Classes,
    /// Interfaces, Components, Packages, UseCases, Dependencies (e.g., mappings), and
    /// Artifacts.
    /// </summary>
    vector<shared_ptr<PackageableElement>> packagedElements_;

    /// <summary>
    /// provided
    /// The Interfaces that the Component exposes to its environment. These Interfaces
    /// may be Realized by the Component or any of its realizingClassifiers, or they may
    /// be the Interfaces that are provided by its public Ports.
    /// </summary>
    vector<shared_ptr<Interface>> provided_;

    /// <summary>
    /// realizations
    /// The set of Realizations owned by the Component. Realizations reference the
    /// Classifiers of which the Component is an abstraction; i.e., that realize its
    /// behavior.
    /// </summary>
    vector<shared_ptr<ComponentRealization>> realizations_;

    /// <summary>
    /// required
    /// The Interfaces that the Component requires from other Components in its
    /// environment in order to be able to offer its full set of provided functionality.
    /// These Interfaces may be used by the Component or any of its
    /// realizingClassifiers, or they may be the Interfaces that are required by its
    /// public Ports.
    /// </summary>
    vector<shared_ptr<Interface>> required_;

};

} // namespace uml
